This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.Make sure that this does not get displayed in the PDF!
This is the template for assignment 1. You can download the qmd-file or copy the code from this rendered document after clicking on </> Code in the top right corner.
Please replace the instructions in this template by your own text, explaining what you are doing in each exercise.
The following will set-up markmyassignment to check your functions at the end of the notebook:
Assignment set:
assignment1: Bayesian Data Analysis: Assignment 1
The assignment contain the following (3) tasks:
- p_red
- p_box
- p_identical_twin
2 Basic probability theory notation and terms
Write your answers here!
3 Basic computer skills
Do some setup here. Explain in text what you do.
# Do some setup:distribution_mean = .2distribution_variance = .01# You have to compute the parameters below from the given mean and variance# distribution_alpha = ...# distribution_beta = ...
3.0.1 (a)
Plot the PDF here. Explain in text what you do.
# Useful functions: seq(), plot() and dbeta()
3.0.2 (b)
Sample and plot the histogram here. Explain in text what you do.
# Useful functions: rbeta() and hist()
3.0.3 (c)
Compute the sample mean and variance here. Explain in text what you do.
# Useful functions: mean() and var()
3.0.4 (d)
Compute the central interval here. Explain in text what you do.
# Useful functions: quantile()
4 Bayes’ theorem 1
4.0.1 (a)
Compute the quantities needed to justify your recommendation here. Explain in text what you do.
# You can do the computation with pen and paper or in R. # Either way, you have to explain why you compute what you compute.
5 Bayes’ theorem 2
You will need to change the numbers to the numbers in the exercise.
Keep the below name and format for the function to work with markmyassignment:
p_red <-function(boxes) {# Do computation here, and return as below.# This is the correct return value for the test data provided above.0.3928571}
5.0.2 (b)
Keep the below name and format for the function to work with markmyassignment:
p_box <-function(boxes) {# Do computation here, and return as below.# This is the correct return value for the test data provided above.c(0.29090909,0.07272727,0.63636364)}
6 Bayes’ theorem 3
6.0.1 (a)
You will need to change the numbers to the numbers in the exercise.
fraternal_prob =1/125identical_prob =1/300
Keep the below name and format for the function to work with markmyassignment:
p_identical_twin <-function(fraternal_prob, identical_prob) {# Do computation here, and return as below.# This is the correct return value for the test data provided above.0.4545455}
7 The three steps of Bayesian data analysis
7.0.1 (a)
markmyassignment
This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.Make sure that this does not get displayed in the PDF!
The following will check the functions for which markmyassignment has been set up:
mark_my_assignment()
✔ | F W S OK | Context
⠏ | 0 | task-1-subtask-1-tests
⠏ | 0 | p_red()
✖ | 1 3 | p_red()
────────────────────────────────────────────────────────────────────────────────
Failure ('test-task-1-subtask-1-tests.R:21:3'): p_red()
p_red(boxes = boxes) not equivalent to 0.5.
1/1 mismatches
[1] 0.393 - 0.5 == -0.107
Error: Incorrect result for matrix(c(1,1,1,1,1,1), ncol = 2)
────────────────────────────────────────────────────────────────────────────────
⠏ | 0 | task-2-subtask-1-tests
⠏ | 0 | p_box()
✖ | 1 3 | p_box()
────────────────────────────────────────────────────────────────────────────────
Failure ('test-task-2-subtask-1-tests.R:19:3'): p_box()
p_box(boxes = boxes) not equivalent to c(0.4, 0.1, 0.5).
3/3 mismatches (average diff: 0.0909)
[1] 0.2909 - 0.4 == -0.1091
[2] 0.0727 - 0.1 == -0.0273
[3] 0.6364 - 0.5 == 0.1364
Error: Incorrect result for matrix(c(1,1,1,1,1,1), ncol = 2)
────────────────────────────────────────────────────────────────────────────────
⠏ | 0 | task-3-subtask-1-tests
⠏ | 0 | p_identical_twin()
✖ | 2 3 | p_identical_twin()
────────────────────────────────────────────────────────────────────────────────
Failure ('test-task-3-subtask-1-tests.R:16:3'): p_identical_twin()
p_identical_twin(fraternal_prob = 1/100, identical_prob = 1/500) not equivalent to 0.2857143.
1/1 mismatches
[1] 0.455 - 0.286 == 0.169
Error: Incorrect result for fraternal_prob = 1/100 and identical_prob = 1/500
Failure ('test-task-3-subtask-1-tests.R:19:3'): p_identical_twin()
p_identical_twin(fraternal_prob = 1/10, identical_prob = 1/20) not equivalent to 0.5.
1/1 mismatches
[1] 0.455 - 0.5 == -0.0455
Error: Incorrect result for fraternal_prob = 1/10 and identical_prob = 1/20
────────────────────────────────────────────────────────────────────────────────
══ Results ═════════════════════════════════════════════════════════════════════
Duration: 0.2 s
[ FAIL 4 | WARN 0 | SKIP 0 | PASS 9 ]
---title: "Assignment 1"author: anonymous # <-- hand in anonymouslyformat: html: toc: true code-tools: true code-line-numbers: true standalone: true self-contained: true embed-resources: true number-sections: true mainfont: Georgia, serif pdf: # documentclass: article geometry: - left=1cm,top=1cm,bottom=1cm,right=7cm number-sections: truereference-location: margincitation-location: margin comments: hypothesis: trueeditor: source---# General information :::: {.content-hidden when-format="pdf"}::: {.callout-warning collapse=false}## Setup *This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.***Make sure that this does not get displayed in the PDF!**This is the template for [assignment 1](assignment1.html). You can download the [qmd-file](./template1.qmd) or copy the code from this rendered document after clicking on `</> Code` in the top right corner.**Please replace the instructions in this template by your own text, explaining what you are doing in each exercise.** The following will set-up `markmyassignment` to check your functions at the end of the notebook:```{r}library(markmyassignment) assignment_path =paste("https://github.com/avehtari/BDA_course_Aalto/","blob/master/assignments/tests/assignment1.yml", sep="")set_assignment(assignment_path) ```:::::::# Basic probability theory notation and terms **Write your answers here!** # Basic computer skills**Do some setup here. Explain in text what you do.**```{r}# Do some setup:distribution_mean = .2distribution_variance = .01# You have to compute the parameters below from the given mean and variance# distribution_alpha = ...# distribution_beta = ...```### (a)**Plot the PDF here. Explain in text what you do.**```{r}# Useful functions: seq(), plot() and dbeta()```### (b)**Sample and plot the histogram here. Explain in text what you do.**```{r}# Useful functions: rbeta() and hist()```### (c)**Compute the sample mean and variance here. Explain in text what you do.**```{r}# Useful functions: mean() and var()```### (d)**Compute the central interval here. Explain in text what you do.**```{r}# Useful functions: quantile()```# Bayes' theorem 1 ### (a)**Compute the quantities needed to justify your recommendation here. Explain in text what you do.**```{r}# You can do the computation with pen and paper or in R. # Either way, you have to explain why you compute what you compute.```# Bayes' theorem 2**You will need to change the numbers to the numbers in the exercise.**```{r}boxes_test <-matrix(c(2,2,1,5,5,1), ncol =2,dimnames =list(c("A", "B", "C"), c("red", "white")))```### (a)**Keep the below name and format for the function to work with `markmyassignment`:**```{r}p_red <-function(boxes) {# Do computation here, and return as below.# This is the correct return value for the test data provided above.0.3928571}```### (b)**Keep the below name and format for the function to work with `markmyassignment`:**```{r}p_box <-function(boxes) {# Do computation here, and return as below.# This is the correct return value for the test data provided above.c(0.29090909,0.07272727,0.63636364)}```# Bayes' theorem 3 ### (a)**You will need to change the numbers to the numbers in the exercise.**```{r}fraternal_prob =1/125identical_prob =1/300```**Keep the below name and format for the function to work with `markmyassignment`:**```{r}p_identical_twin <-function(fraternal_prob, identical_prob) {# Do computation here, and return as below.# This is the correct return value for the test data provided above.0.4545455}```# The three steps of Bayesian data analysis### (a):::: {.content-hidden when-format="pdf"}::: {.callout-warning collapse=false}## markmyassignment*This block will only be visible in your HTML output, but will be hidden when rendering to PDF with quarto for the submission.***Make sure that this does not get displayed in the PDF!**The following will check the functions for which `markmyassignment` has been set up:```{r}mark_my_assignment() ```:::::::